package order;

import beans.Good;

import java.util.List;

public class GoodsDao extends BasicDao<Good>{
    // 显示所有商品
    public List<Good> showAllData(){
        return queryMulti("SELECT * FROM `goods`",Good.class);
    }

    // 删除数据（根据ID）
    public Boolean deleteData(String good_id){
        return dmlData("DELETE FROM `goods` WHERE `goods_id`=" + good_id);
    }
    // 添加数据
    public Boolean addData(Good goods){
        return dmlData("INSERT INTO `goods`(`goods_name`,`unitprice`,`stock`) VALUES('"+ goods.getGoods_name() +"',"+ goods.getUnitprice() +","+ goods.getStock() +")");
    }

    // 修改数据
    public Boolean updateData(Good goods){
        return dmlData("UPDATE `goods` SET `goods_name`='"+ goods.getGoods_name() +"',`unitprice`="+ goods.getUnitprice() +",`stock`="+ goods.getStock() +" WHERE `goods_id`='"+ goods.getGoods_id() +"'");
    }

    // 显示单条数据
    public Good singleData(String good_id){
        return querySingle("SELECT * FROM `goods` WHERE `goods_id`='" + good_id+"'",Good.class);
    }
}
